/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.meteocal.entities;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "notification")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Notification.findAll", query = "SELECT n FROM Notification n"),
    @NamedQuery(name = "Notification.findByIdn", query = "SELECT n FROM Notification n WHERE n.idn = :idn"),
    @NamedQuery(name = "Notification.findByDate", query = "SELECT n FROM Notification n WHERE n.date = :date"),
    @NamedQuery(name = "Notification.findByType", query = "SELECT n FROM Notification n WHERE n.type = :type")})
public class Notification implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "IDN")
    private Integer idn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SendingDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "Type")
    private String type;
    @Column(name = "ProposedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date proposedDate;    
    @JoinColumn(name = "EventID", referencedColumnName = "IDE")
    @ManyToOne(optional = false)
    private Event eventID;

    public Notification() {
    }

    public Notification(Integer idn) {
        this.idn = idn;
    }

    public Notification(Integer idn, Date sendingDate, String type, Date proposedDate, Event event) {
        this.idn = idn;
        this.date = sendingDate;
        this.type = type;
        this.proposedDate = proposedDate;
        this.eventID = event;
    }

    public Integer getIdn() {
        return idn;
    }

    public void setIdn(Integer idn) {
        this.idn = idn;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    
    public String getFormatDate(){
        Locale.setDefault(Locale.ENGLISH);
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy");
        String dataString = sdf.format(this.date);
        return dataString;
    }
    public String getFormatHour(){
        SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
        String hourString = sdf.format(this.date);
        return hourString;
    }
    
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
    
    public Date getProposedDate(){
        return proposedDate;
    }
    
    public void setProposedDate(Date proposedDate){
        this.proposedDate = proposedDate;
    }
    
    public String getFormatProposedDate(){
        if(this.proposedDate != null){
            Locale.setDefault(Locale.ENGLISH);
            SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy");
            String dataString = sdf.format(this.proposedDate);
            return dataString;
        }
        else return "";
    }    

    public Event getEventID() {
        return eventID;
    }

    public void setEventID(Event eventID) {
        this.eventID = eventID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idn != null ? idn.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Notification)) {
            return false;
        }
        Notification other = (Notification) object;
        if ((this.idn == null && other.idn != null) || (this.idn != null && !this.idn.equals(other.idn))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.meteocal.entities.Notification[ idn=" + idn + " ]";
    }
    
}
